package com.example.demo.controller;

import java.util.Random;

import java.util.Random;

public class UserDataGenerator {
    public static void main(String[] args) {
        Random random = new Random();

        for (int i = 1; i <= 1000; i++) { // 假设我们生成1000条记录
            String id = i + ""; // ID从1开始自增
            String name = generateRandomName(random.nextInt(10) + 1); // 随机长度1-10个字符
            String phone = generateRandomPhoneNumber(); // 保证电话号码始终是10位数字

            System.out.println("INSERT INTO user (id, name, phone) VALUES ('" +
                    id + "', '" +
                    name + "', '" +
                    phone + "');");

        }
    }

    public static String generateRandomName(int maxLength) {
        String allowedChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";
        Random random = new Random();
        int length = random.nextInt(maxLength) + 1;
        StringBuilder sb = new StringBuilder(length);
        for (int i = 0; i < length; i++) {
            int randomIndex = random.nextInt(allowedChars.length());
            sb.append(allowedChars.charAt(randomIndex));
        }
        return sb.toString().trim();
    }

    public static String generateRandomPhoneNumber() {
        String numbers = "0123456789";
        Random random = new Random();
        int phoneNumberLength = random.nextInt(10) + 1; // 生成1到10位的随机电话号码长度
        StringBuilder sb = new StringBuilder(phoneNumberLength);
        for (int i = 0; i < phoneNumberLength; i++) {
            sb.append(numbers.charAt(random.nextInt(numbers.length())));
        }
        return sb.toString();
    }
}
